package llf.cool.model.impl;

import java.util.List;
import java.util.Map;

import llf.cool.model.TrackDownload;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class TrackDownloadBuilder {

	public TrackDownload build(JSONObject object) throws JSONException{
		
		TrackDownload trackDownload = new TrackDownload();
		trackDownload.setError(object.getInt("error"));
		trackDownload.setResId(object.getInt("res_id"));
		trackDownload.setDownUrl(object.getString("down_url"));
		trackDownload.setUserScore(object.getString("user_score"));
		trackDownload.setResScore(object.getString("res_score"));
		
		Log.i("TrackDownloadBuilder", " ");
		Log.i("TrackDownloadBuilder", "error="+object.getInt("error"));
		Log.i("TrackDownloadBuilder", "res_id="+object.getInt("res_id"));
		Log.i("TrackDownloadBuilder", "down_url="+object.getString("down_url"));	
		Log.i("TrackDownloadBuilder", "user_score="+object.getString("user_score"));
		Log.i("TrackDownloadBuilder", "res_score="+object.getInt("res_score"));
		Log.i("TrackDownloadBuilder", " ");
		
		return trackDownload;
	}
	
	public TrackDownload build(List<Map<String, String>> list){
		TrackDownload trackDownload = new TrackDownload();
		trackDownload.setError( Integer.valueOf( (list.get(0).get("error")) ) );
		trackDownload.setResId( Integer.valueOf( (list.get(1).get("res_id")) ) );
		trackDownload.setDownUrl(list.get(2).get("down_url"));
		trackDownload.setUserScore(list.get(3).get("user_score"));
		trackDownload.setResScore(list.get(4).get("res_score"));
		
		Log.i("TrackDownloadBuilder", " ");
		Log.i("TrackDownloadBuilder", "error="+Integer.valueOf( (list.get(0).get("error")) ));
		Log.i("TrackDownloadBuilder", "res_id="+Integer.valueOf( (list.get(1).get("res_id")) ));
		Log.i("TrackDownloadBuilder", "down_url="+list.get(2).get("down_url"));	
		Log.i("TrackDownloadBuilder", "user_score="+list.get(3).get("user_score"));
		Log.i("TrackDownloadBuilder", "res_score="+list.get(4).get("res_score"));
		Log.i("TrackDownloadBuilder", " ");
		
		return trackDownload;
	}
}
